package com.example.common;

import com.example.exception.ParmrterException;
import com.example.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class ResultException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultVO handleException(Exception e) {
        log.error("Caused by:",e);
        ResultVO resultVO = null;
        if(e instanceof ParmrterException)
             resultVO = new ResultVO(((ParmrterException) e).getCode(),e.getMessage());
        else
             resultVO = new ResultVO(0,"系统内部异常");
        return resultVO;

    }


}
